package org.sandbox2.domain.loan;

import org.sandbox2.reference.LoanType;
import org.springframework.beans.BeanUtils;

public class LoanFactory {
	
	public static Loan createLoan(Loan loan) {
		
		Loan concreteLoan = null;
		
		if (loan.getLoanType() == LoanType.Flat) {
			concreteLoan = new FlatLoan();
		}
		
		if (loan.getLoanType() == LoanType.InterestOnly) {
			concreteLoan = new InterestOnlyLoan();
		}
		
		BeanUtils.copyProperties(loan, concreteLoan);
		concreteLoan.setDescription("FlatLoan created by Factory");
		
		return concreteLoan;
	}

}
